/**
 * Project: Utilities <br>
 * Package: org.leumasjaffe.builder
 */
package org.leumasjaffe.builder;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
 * Class org.leumasjaffe.builder.OneShotConstructorBuilder in file OneShotConstructorBuilder.java <br>
 * 
 * @author leumasjaffe
 * @version Jun 9, 2013
 * Created on: Jun 9, 2013
 * 
 * @param <T>
 * 
 */
@NonNullByDefault
public abstract class OneShotDelegateBuilder<T> extends CheckedDelegateBuilder<T> 
implements OnceBuilder<T> {
	
	private boolean built = false;

	/**
	 * @param numArgs
	 */
	public OneShotDelegateBuilder(int numArgs) {
		super(numArgs);
	}
	
	@Override
	public T build() {
		validateUnbuiltOrThrow();
		return super.build();
	}

	/**
	 * 
	 */
	private void validateUnbuiltOrThrow() {
		if (alreadyBuilt()) {
			throw new BuilderAlreadyBuiltException("This builder can only build the object once.");
		}
	}

	/* (non-Javadoc)
	 * @see org.leumasjaffe.builder.OnceBuilder#alreadyBuilt()
	 */
	@Override
	public boolean alreadyBuilt() {
		return this.built;
	}

}
